﻿


/*********************
 *      INCLUDES
 *********************/

#if defined(LV_LVGL_H_INCLUDE_SIMPLE)
#include "user_knob_config.h"
#else
#include "user_app/user_knob_config.h"
#include <Windows.h>
#include "resource.h"
#endif

lv_obj_t* prj_parent_cont = NULL;
lv_obj_t* prj_prev_cont = NULL;

lv_indev_t* g_indev_keypad=NULL;
lv_group_t* g_group=NULL;


#include "user_page_config.h"

page_config_t page_config={0};

static void event_handler(lv_event_t* e)
{
    lv_event_code_t event = lv_event_get_code(e);
    if (event == LV_EVENT_KEY)
    {
        uint32_t* key = lv_event_get_param(e);
        printf("key_code %d \n", *key);
    }
    else if (event == LV_EVENT_CLICKED)
    {
        printf("LV_EVENT_CLICKED event=%d\r\n", event);
    }
    //printf("event code %d \n", event);
    //printf("event code %d \n", event);
}

void knob_gui_init(void)
{
    prj_parent_cont = lv_obj_create(lv_scr_act());
    lv_obj_set_style_pad_all(prj_parent_cont, 0, 0);
    lv_obj_set_style_border_width(prj_parent_cont, 0, 0);
    lv_obj_set_size(prj_parent_cont, LV_PCT(100), LV_PCT(100));
    lv_obj_add_flag(prj_parent_cont, LV_OBJ_FLAG_SCROLL_ONE);
    lv_obj_set_scroll_snap_x(prj_parent_cont, LV_SCROLL_SNAP_CENTER);
    lv_obj_set_scroll_snap_y(prj_parent_cont, LV_SCROLL_SNAP_CENTER);
    lv_obj_set_scrollbar_mode(prj_parent_cont, LV_SCROLLBAR_MODE_OFF);
    lv_obj_clear_flag(prj_parent_cont, LV_OBJ_FLAG_SCROLL_ELASTIC);
	lv_obj_set_style_bg_color(lv_scr_act(), lv_color_make(0,0,0), 0);//设置背景颜色为黑�?	
    lv_obj_add_event_cb(prj_parent_cont, event_handler, LV_EVENT_ALL, NULL);

    prj_prev_cont = lv_obj_create(prj_parent_cont);
    g_group = lv_group_create();
    lv_indev_set_group(g_indev_keypad, g_group);
    lv_group_set_default(g_group);         //设置组(group)为默认模式,后面的部件创建时会自动加入组(group)
	lv_obj_set_style_bg_color(prj_parent_cont, lv_color_make(0,0,0), 0);//设置背景颜色为黑�?
	 


	if(1)   //默认配置
	{	
			page_config.current_page 	= MAIN_MENU;
            page_config.last_page =       MAIN_MENU;
			page_config.language_type   = CHINESE;
	}


	if(page_config.current_page == MAIN_MENU){
		 user_main_page_entry(prj_prev_cont);
	}else if(page_config.current_page == SETTING_MENU){
       user_setting_page_entry(prj_prev_cont);
    }
    else if(page_config.current_page == WINDOW_MENU)
    {
        user_window_page_entry(prj_prev_cont, DISPLAY_WINDOW_ADD_DEV1);
    }
    else if(page_config.current_page == PAIRED_MENU)
    {

        user_paired_page_entry(prj_prev_cont);
    }
	
	
		//knob_home_page_entry(prj_prev_cont);
    /*knob_seting_page_entry(prj_prev_cont);*/
    //knob_wash_page_entry(prj_prev_cont);
    //knob_power_page_entry(prj_prev_cont);
    /*knob_temp_page_entry(prj_prev_cont);*/
   // lv_timer_create(ui_test_timer_cb, 100, prj_prev_cont);
}

//切面切换函数 page 参数 参考 MENU
void Menu_Switch_Callback(MENU current_page, MENU last_page)
{
    //释放上一个界面对象
    printf("current %d last %d\r\n", current_page, last_page);
    switch (last_page)
    {
    case PAIRED_MENU:
        user_paired_page_exit(prj_prev_cont);
        lv_obj_clean(prj_parent_cont);
        prj_prev_cont = lv_obj_create(prj_parent_cont);
        //user_paired_page_entry(prj_prev_cont);
        printf("%s PAIRED_MENU\r\n", __FUNCTION__);
        break;

    case RESET_MENU:
        printf("%s RESET_MENU\r\n", __FUNCTION__);

        break;

    case SHUTDOWN_MENU:
        printf("%s SHUTDOWN_MENU\r\n", __FUNCTION__);
        break;
   
    case MAIN_MENU:
        printf("%s MAIN_MENU\r\n", __FUNCTION__);
        user_main_page_exit(prj_prev_cont);
        lv_obj_clean(prj_parent_cont);
        prj_prev_cont = lv_obj_create(prj_parent_cont);
        break;

    case LANGUAGE_MENU:
        printf("%s LANGUAGE_MENU\r\n", __FUNCTION__);
    case SETTING_MENU:
        printf("%s SETTING_MENU\r\n", __FUNCTION__);
        user_setting_page_exit(prj_prev_cont);
        lv_obj_clean(prj_parent_cont);
        prj_prev_cont = lv_obj_create(prj_parent_cont);
        break;

    default:break;
    }




    switch (current_page)
    {
            case PAIRED_MENU:
                user_paired_page_entry(prj_prev_cont);
                printf("%s PAIRED_MENU\r\n",__FUNCTION__);
                break;

            case RESET_MENU:
                printf("%s RESET_MENU\r\n", __FUNCTION__);

                break;

            case SHUTDOWN_MENU:
                printf("%s SHUTDOWN_MENU\r\n", __FUNCTION__);
                break;

            case MAIN_MENU:
                user_main_page_entry(prj_prev_cont);
                printf("%s MAIN_MENU\r\n", __FUNCTION__);
                break;

            case LANGUAGE_MENU:
                printf("%s LANGUAGE_MENU\r\n", __FUNCTION__);
            case SETTING_MENU:
                user_setting_page_entry(prj_prev_cont);
                printf("%s SETTING_MENU\r\n", __FUNCTION__);
                break;

                default:break;
    }


}

//界面事件函数 page 参数 参考 MENU  
void Menu_Send_Event(uint8_t event,uint8_t code)
{ 
        if (event == LV_EVENT_MENU_CHANGE)
        {
            lv_event_send(prj_prev_cont, LV_EVENT_MENU_CHANGE, (void*)&code);
        }
        else if (event == LV_EVENT_WINDOW)
        {
            lv_event_send(prj_prev_cont, LV_EVENT_WINDOW, (void*)&code);
        }
}
void Window_Display_Callback(WINDOW_Type_t type,lv_obj_t *parent)
{

    page_config.window_type = type;

    if (type != DISPLAY_WINDOW_OFF)
    {
        if (page_config.window_is_runing == true)
        {
            return;
        }
        user_window_page_entry(prj_prev_cont, page_config.window_type);
    }
    else
    {
        if (page_config.window_is_runing == true)
        {
            printf("lv_obj_get_child_cnt = %d\r\n", lv_obj_get_child_cnt(page_config.window_obj));
            user_window_page_exit((page_config.window_obj));

        }
    }

    extern lv_indev_t* g_indev_keypad;
    //g_group = lv_group_create();
    lv_indev_set_group(g_indev_keypad, g_group);
    lv_group_set_default(g_group);         //设置组(group)为默认模式,后面的部件创建时会自动加入组(group)
    

}



